/*
 * $Id$
 */
package py.windmill.web.dict;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author myang
 */
public class Word {
    private String _text;
    private List<Entry> _entries;
    private int _selectedEntryIndex;

    public Word(final String text) {
        _text = text;
        _entries = new ArrayList<Entry>();
    }

    public Word add(final String entry) {
        return add(entry, "");
    }

    public Word add(final String entry, final String definition) {
        _entries.add(new Entry(entry, definition));
        return this;
    }

    public String getText() {
        return _text;
    }

    public List<Entry> getEntries() {
        return _entries;
    }

    public Word setSelectedEntryIndex(final int i) {
        _selectedEntryIndex = i;
        return this;
    }

    public int getSelectedEntryIndex() {
        return _selectedEntryIndex;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("[");
        sb.append(_text).append("]\n");
        for (final Entry e : getEntries()) {
            sb.append(e.getText()).append(" : ").append(e.getDefinition())
              .append("\n");
        }
        return sb.toString();
    }
}
